package com.atguigu.educms.controller;

import com.atguigu.commonutils.R;

import com.atguigu.educms.CmsApplication;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("获取前端轮播图")
@RestController
@RequestMapping("/educms/bannerfront")
@CrossOrigin
public class BannerFrontController {

    @Autowired
    CrmBannerService crmBannerService;

    @ApiOperation(value = "查询所有轮播图带分页")
    @GetMapping("getAllBannerPage")
    public R getAllBannerPage() {
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("sort");
        wrapper.last("limit 3");
        List<CrmBanner> list = crmBannerService.list(wrapper);
        return R.ok().data("Banners", list);
    }
    @Cacheable(value = "banner",key = "'selectIndexList'")
//    @Cacheable(cacheNames = {"banner","banner001"},condition = "#id > 1")  //如果有带参数的id可以做条件
//    @Cacheable(cacheNames = {"banner","banner001"} ,key = "'selectIndexList111'")  //如果有带参数的id可以做条件
//  要使用redis缓存注解，结果集必须是集合或者map等，不能是R这样的工具类，所以去service去写这个方方加上缓存注解
    @ApiOperation(value = "查询轮播图带使用redis缓存")
    @GetMapping("getAllBanner")
    public R getAllBanner(){
        List<CrmBanner> list =crmBannerService.selectAllBanner();
        return R.ok().data("Banners",list);
    }


}
